package 单周赛.history;

import java.util.HashSet;
import java.util.Set;

/**
 *
 */
public class 第347场单周赛 {

    public static void main(String[] args) {


    }

    public String removeTrailingZeros(String num) {
        int idx = num.length() - 1;
        while (idx >= 0 && num.charAt(idx) == '0') {
            idx--;
        }
        return num.substring(0, idx + 1);
    }

    public int[][] differenceOfDistinctValues(int[][] grid) {
        int[][] ans = new int[grid.length][grid[0].length];

        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                Set<Integer> topLeftSet = new HashSet<>();
                Set<Integer> bottomTightSet = new HashSet<>();

                int lRow = i - 1, lColumn = j - 1;
                while (lRow >= 0 && lColumn >= 0) {
                    topLeftSet.add(grid[lRow][lColumn]);
                    lRow--;
                    lColumn--;
                }
                int rRow = i + 1, rColumn = j + 1;
                while (rRow < grid.length && rColumn < grid[0].length) {
                    bottomTightSet.add(grid[rRow][rColumn]);
                    rRow++;
                    rColumn++;
                }

                ans[i][j] = Math.abs(topLeftSet.size() - bottomTightSet.size());
            }
        }

        return ans;
    }

}
